// pages/01/01.js
import {
    Net
} from '../../utils/Net'
const net = new Net()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        avatar: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.bzwz.com%2Fimg%2Fdefault%2Fnot_loaded.jpg&refer=http%3A%2F%2Fwww.bzwz.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1652362257&t=394c6bdd8bdfc367eeefa07a4656e9c0',
        name: '',
        phone: '',
        password: '',
        isDisable: true
    },
    InputPhone(e) {
        this.setData({
            phone: e.detail.value
        })
        this._checkBtn()
    },
    InputPass(e) {
        this.setData({
            password: e.detail.value
        })
        this._checkBtn()
    },
    _checkBtn() {
        const hasPhone = this.data.phone.length === 11
        const hasPass = this.data.password.length >= 6
        const hasname = this.data.name.length >= 1
        this.setData({
            isDisable: !(hasPass && hasPhone && hasname)
        })
    },
    async TapLogin() {
        // const opt={
        //     name:this.data.name

        // }
        const ans = await net.Post('s/reg', this.data)
        wx.showToast({
            title: ans.msg,
            icon: 'none'
        })
        wx.navigateTo({
            url: '/pages/s_login/01',
        })
    },
    TapAuth() {
        wx.getUserProfile({
            desc: '为了提供更好的购物体验',
            success: (e) => {

                const u = e.userInfo
                this.setData({
                    name: u.nickName,
                    avatar: u.avatarUrl
                })
                this._checkBtn()
            },
            fail: (e) => {
                wx.showToast({
                    title: '登录失败',
                    icon: 'error'
                })
            },

        })
    },


    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})